package dataStructure.linkedlist;

//失败
public class Solution {
    public static ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {

        ListNode temp1 = list1;
        for (int i = 0;i<a-1;i++){
            temp1 = temp1.next;
        }
        ListNode temp2 =temp1.next;
        for (int i = a;i<b;i++){
            temp2 = temp2.next;
        }
        temp2 = temp2.next;  //到b+1结点
        //3.找到链表2的尾节点
        ListNode tail = list2;
        while (true){
            if (tail.next==null){
                break;
            }
            tail = tail.next;
        }
        //4.将链表2插入到链表1的第a个和第b个节点之间
        temp1.next = list2;
        tail.next = temp2;

        return list1;

    }

}
class ListNode{
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
